/* Test1.cs -- 
   Copyright (C) 2008  Casey Marshall.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */


using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using NUnit.Framework;

using SexpSharp.Remoting;

namespace SexpSharp.Remoting.Tests
{
    public interface IHello
    {
        string HelloWorld();
    }

    public class Hello : MarshalByRefObject, IHello
    {
        public string HelloWorld()
        {
            return "Hello, World!";
        }
    }

    [TestFixture]
    public class Test1
    {
        [Test]
        public void a()
        {
            setupRemotingChannel();
            registerService();
            runRemote();
        }

        void setupRemotingChannel()
        {
            Hashtable props = new Hashtable();
            props["port"] = 6000;
			props["name"] = "RemotingTest1";
            SexpServerFormatterSinkProvider serv =
                new SexpServerFormatterSinkProvider();
            SexpClientFormatterSinkProvider cli =
                new SexpClientFormatterSinkProvider();
            TcpChannel channel = new TcpChannel(props, cli, serv);
            ChannelServices.RegisterChannel(channel, false);
        }

        void registerService()
        {
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello),
                                                               "hello",
                                                               WellKnownObjectMode.Singleton);
        }

        void runRemote()
        {
            IHello hello = (IHello) Activator.GetObject(typeof(IHello),
                                                        "tcp://localhost:6000/hello");
            Console.WriteLine(hello.HelloWorld());
        }
    }
}